package com.fuxian.dao.mybatisImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import com.fuxian.dao.LessonItemDao;
import com.fuxian.model.Lessonitem;

@Repository
public class LessonItemDaoMybatisImpl implements LessonItemDao {

	@Resource
	private SqlSessionTemplate sqlSessionTemplate;
	public void addLessonItem(Lessonitem lessonitem) {
		sqlSessionTemplate.insert("addLessonItem", lessonitem);

	}

	public void deleteLessonItemById(int id) {
	sqlSessionTemplate.delete("deleteLessonItemById", id);

	}

	public void modifyLessonItem(Lessonitem lessonitem) {
		sqlSessionTemplate.update("modifyLessonItem", lessonitem);

	}

	public List<Lessonitem> selectAlllLessonItem(int start, int size) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("start", start);
		map.put("size", size);
		return sqlSessionTemplate.selectList("selectAlllLessonItem", map);
	}

	public List<Lessonitem> selectLessonItemByClassifId(int classifId) {
		return sqlSessionTemplate.selectList("selectLessonItemByClassifId", classifId);
	}

	public Lessonitem selectLessonItemByLessonId(int lessonId) {
		return sqlSessionTemplate.selectOne("selectLessonItemByLessonId", lessonId);
	}

	public int selectCount(int classifId) {
		if(classifId==-1){
		return	sqlSessionTemplate.selectOne("selectLessonCount", classifId);
		}else{
		return 	sqlSessionTemplate.selectOne("selectLessonCountByClassifId", classifId);
		}
	}

}
